package com.ltmonitor.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.github.miemiedev.mybatis.paginator.domain.Paginator;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ltmonitor.dao.IBaseIbatisDao;
import com.ltmonitor.service.IQueryService;
import com.ltmonitor.vo.PaginateResult;

/**
 * 基于Ibatis的分页和不分页的查询服务
 * @author www.jt808.com
 *
 */

@Service("queryService")
public class QueryService implements IQueryService {

	@Autowired
	IBaseIbatisDao baseIbatisDao;

	@Override
	public PaginateResult queryByPagination(String queryId,
			Map params, int pageNo, int pageSize) {
		//PageBounds pageBounds = new PageBounds(pageNo, pageSize);
		//PageList pageList = (PageList)baseIbatisDao.queryByPagination(queryId, params, pageBounds);
		
		//Paginator p = pageList.getPaginator();
		Page p = PageHelper.startPage(pageNo, pageSize,true);
		List result = baseIbatisDao.query(queryId, params);
		
		//List itemList = new ArrayList(pageList);		
		//return new PaginateResult(p.getTotalCount(), result);
		return new PaginateResult(p.getTotal(), result);
	}

	@Override
	public List<Map<String, Object>> query(String queryId, Map params) {
		return baseIbatisDao.query(queryId, params);
	}
	

	@Override
	public void update(final String statementName, Object paramMap)
	{
		baseIbatisDao.update(statementName, paramMap);
	}
	@Override
	public void insert(final String statementName, Object paramMap)
	{
		baseIbatisDao.insert(statementName, paramMap);
	}
	
	

}
